package sample;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import java.io.File;
import java.util.List;


public class Controller {
	@FXML
	private Button inputFileBtn;//输入文件选择按钮
	@FXML
	private Button inputDirectoryBtn;//输入目录选择按钮
	@FXML
	private Button outputBtn;//输出目录选择按钮
	@FXML
	private TextField inputField;//输入路径
	@FXML
	private TextField outputField;//输出路径

	public Stage stage;
	//public Controller(){};
	//public Controller(Stage stage){this.stage = stage;initial();};
	public void initial() {
		inputFileBtn.setOnMouseClicked(event ->{
			FileChooser fc = new FileChooser();
			fc.setTitle("选择文件");
			fc.selectedExtensionFilterProperty();
			fc.getExtensionFilters().addAll(
					new FileChooser.ExtensionFilter("All", "*.*")
			);
			List<File> list =  fc.showOpenMultipleDialog(stage);
			StringBuilder sb = new StringBuilder();
			list.forEach(item ->{
				sb.append(item.getName()).append(",");
			});
			inputField.setText(sb.toString().substring(0,sb.length()-1));
		});

		inputDirectoryBtn.setOnMouseClicked(event ->{
			inputField.setText(showDialog());
		});

		outputBtn.setOnMouseClicked(event->{
			outputField.setText(showDialog());
		});
	}

	private String showDialog(){
		DirectoryChooser dc = new DirectoryChooser();
		dc.setTitle("选择目录");
		File directory = dc.showDialog(stage);
		return directory.getAbsolutePath();
	}

}
